
#@homejs()
#@checkToken2()
<script src="/assets/js/dateclick/WdatePicker.js"></script>
<link href="/assets/js/dateclick/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<div style="width:880px;min-height:600px;"> 

	<!--时间筛选-->
	<div align="left" style="background:#FFF;padding-left:20px;line-height:50px;height:50px;width:860px;">
		<span>收益总额：</span>
		<span id="total" style="color:#fe425a;font-size:20px;"></span>
	</div>
	<!--标的列表--> 
	<div align="left" style="padding:10px 20px 20px 20px;;width:840px;height:600px;background:#FFF;">
		<div style="line-height:50px;font-size:14px;height:550px;">
			<div align="center" style=" border-bottom:1px dashed #e0e0e0;height:50px;background:#fafafa">
				<div style="float:left;width:250px;">推荐用户</div>
				<div style="float:left;width:250px;">推荐时间</div>
				<div style="float:left;width:250px;">赚取收益</div>
				
			</div>
			<div id="friendlist">
				
			</div>
		</div>
		<!--分页-->
		<div align="center" style="font-size:14px;height:50px;width:100%;padding-bottom:10px;background:#FFF;line-height:50px;">
			<span id="firstpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:5px 0 0 5px;">
				首页
			</span>
			<span id="backpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				上一页
			</span>
			<span style="padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				第<span id="pageNumber"></span>页&nbsp&nbsp共<span id="totalPage"></span>页
			</span>
			<span id="nextpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				下一页
			</span>
			<span id="lastpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:0 5px 5px 0;">
				尾页
			</span>
			<span style="margin-left:50px;">第</span>
			<input id="pagenum" style="border:1px solid #ebebeb;border-radius:5px;height:32px;width:40px;padding:0 10px 0 10px;font-size:16px;"  /> 
			<span>页</span>
			<span id="gopage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:5px;">
				跳转
			</span>
		</div>
	</div>
</div>

<script id="demo" type="text/x-jquery-tmpl">
	<div align="center" style="border-bottom:1px dashed #e0e0e0;height:50px;">
		<div class="onellipsis" style="float:left;width:250px;color:#fa4357">${mobile}</div>
		<div class="onellipsis" style="float:left;width:250px;">${create_time}</div>
		<div style="float:left;width:250px;">￥${amount}</div>
	</div>
</script>
<script>
	var pageNumber = "";
	var page = 1;
	var totalPage = "";
	mytradelist(page);
	//上一页
	$("#backpage").click(function(){
		page = page-1;
		if(page <= 0){
			layer.msg("当前已是首页！",{icon:2,time:1000}); 
		}else{
			$("#friendlist").empty();
			mytradelist(page);
		}
	}); 
	//下一页
	$("#nextpage").click(function(){
		page = page + 1;
		if(page > totalPage){
			layer.msg("当前已是尾页！",{icon:2,time:1000}); 
		}else{
			$("#friendlist").empty();
			mytradelist(page);
		}
	}); 
	//首页
	$("#firstpage").click(function(){ 
		page = 1;
		$("#friendlist").empty();
		mytradelist(page);
	}); 
	//尾页
	$("#lastpage").click(function(){
		page = totalPage;
		$("#friendlist").empty();
		mytradelist(page);
	});  
	//跳转
	$("#gopage").click(function(){
		page = $("#pagenum").val();
		if(page > totalPage || page < 1 ){
			layer.msg("输入页数不在区间内！",{icon:2,time:1000}); 
		}else{ 
			$("#friendlist").empty();
			mytradelist(page);
		}
	});
	function mytradelist(page){
		$.getJSON("#(path)/user/friends?token=#(session.token??)&size=10&page="+page, function(datalist) {
			console.log(datalist);
			console.log(1);
			$("#total").html(datalist.data.total+"元");
			totalPage = datalist.data.page.totalPage;
			pageNumber = datalist.data.page.pageNumber;
			if(totalPage==0){
				totalPage = 1;
			}
			if(pageNumber==0){
				pageNumber = 1; 
			}
			$("#totalPage").html(totalPage);
			$("#pageNumber").html(pageNumber);
			$.each(datalist.data.page.list, function(i, item){ 
				//console.log(item);
				console.log(item.id); 
				var mobile = item.mobile.substr(0,3)+"****"+item.mobile.substr(7,11);
				var invests = {mobile:mobile,amount:item.amount,create_time:item.create_time}; 
				$("#demo").tmpl(invests).appendTo('#friendlist'); 
			});
			 
			
		});
	}
</script>

